package com.nervenets.general.model;

import com.nervenets.general.enumeration.SqlFun;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class SqlFunField implements Serializable {
    @ApiModelProperty(value = "mysql功能函数")
    private SqlFun fun = SqlFun.none;
    @ApiModelProperty(value = "字段名")
    private String name;
    @ApiModelProperty(value = "该字段需要转换的类型")
    private Class<?> cast;

    public SqlFunField(String name) {
        this.name = name;
    }

    public String alias() {
        if (SqlFun.none.equals(fun)) return this.name;
        return this.fun.getValue() + "_" + this.name;
    }
}
